home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / CTools 2.2.1d / CTools / CTools.rsrc / styl_143_Formatting.rtf < prev    next >
Encoding:
Text File  |  1995-12-01  |  8.6 KB  |  4 lines

  1. {\rtf1\ansi
  2. {\fonttbl\f0\fswiss Times;\f1\fswiss Courier;}
  3. {\colortbl\red0\green0\blue0;\red0\green0\blue221;\red221\green0\blue0;\red0\green51\blue153;\red0\green0\blue170;\red170\green0\blue0;}
  4. \f0\b0\i0\outl0\shad0\fs48 \cf0 \expan0 \ul0 C Source Formatter:\line \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 \line The \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  C source formatter works beautifully.  It only works on files suffixed in \u8220".c\u8221" though.  \line \line The C source formatter will operate on a \u8220"Command 1\u8221" key combination on the open file, whereupon it does it and replaces the ext in the file with the formatted text.  If you want to keep this, then close and save, or vice versa.  Otherwise you MUST select \u8220"Save As\u8221" from the file menu if you do not want your original source altered.\line \line I have never had an error in its output as long as the input was \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 compilable \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 code and not too big.  Sometimes it will balk on a BIG\u160 file, or one with some unusual weirdnesses.  But that\u8217's very rare.  If it does do this, it will merely crash without eating your file (hopefully).  What I do, when I KNOW I have too big a file to format, is split it up.  Open the \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  \u8220"WorkSheet.c\u8221" file, select half the file to be processed file, copy it, paste it into the worksheet, format it, select all, cut, save the worksheet, switch back to the intended file and paste and save.  Then select the other half.  You can do this between your editor and \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  or all in \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 .\line \line The formatter doubles as a \u8220"C check\u8221" function, in that if there is a missing brace or missing semicolon or missing paren, the Source Formatter output will have odd indents immediately afterward.  You can correct these glitches right in the \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  window.  Scroll down until the code looks oddly indented, find the omission, add it, and run the formatter again.\line \line If you have a missing \u8220"case\u8221" keyword before a \u8216':\u8217' then \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  will not indent that line, so those are easy to find.\line \line You can also paste a routine into a new \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  document being used as a \u8220"worksheet\u8221" and format it, then cut or copy it out.  The file must be \u8220"saved\u8221" with the \u8220".c\u8221" suffix in order for it to work.  But if you want to pump code and not deal with indents until you are done, then just have \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  running in MultiFinder and, when you\u8217're done typing, select all and copy, paste into your \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  \u8220"worksheet.c\u8221", hit Command 1, select all and cut again, save the worksheet.c file (save empty) and then paste your source back into your code file.\line \line One tip on big files, suppose you have a huge routine and \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  doesn\u8217't have enough \u8220"poop\u8221" to process it?  Simply:\line \line \f1\b0\i0\outl0\shad0\fs20 \cf3 \expan0 \ul0 ( 1) Move the insertion point to the top of the file in your code editor.\line ( 2) Drag the scroll thimb halfway down.\line ( 3) Hold SHIFT and click near the left margin.\line ( 4) Command V.\line ( 5) Switch to the \f1\b0\i0\outl0\shad0\fs20 \cf4 \expan0 \ul0 C\f1\b0\i0\outl0\shad0\fs20 \cf5 \expan0 \ul0 Tools\f1\b0\i0\outl0\shad0\fs20 \cf5 \expan0 \ul0 \u8482?\f1\b0\i0\outl0\shad0\fs20 \cf3 \expan0 \ul0  Worksheet.c window.\line ( 6) Command 1.\line ( 7) Command A.\line ( 8) Command X.\line ( 9)Commad S.\line (10) Switch back to your editor.\line (11) Command V.  \line \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 \line Now, the tricky part...\line \line You\u8217'll want the remaining, unformatted source from the file to have the same indent as the part it goes under IF you are mid-routine.  If you format the remainder the way it is, missing begin braces will result in mismatched indents.  So, do this:\line \line \f1\b0\i0\outl0\shad0\fs20 \cf3 \expan0 \ul0 ( 1) Put the insertion point just before the first character of the last \line         line of the code you just formatted.\line ( 2) Hit the left arrow and count how many times you hit it to get the\line         insertion point to the left margin.\line ( 3) Hit the down arrow to get below that code.\line ( 4) Drag the scroll thumb to the bottom of the file.\line ( 5) Hold Shift and click past the end of all the code.\line ( 6) Command C.\line ( 7) Switch back to the \f1\b0\i0\outl0\shad0\fs20 \cf4 \expan0 \ul0 C\f1\b0\i0\outl0\shad0\fs20 \cf5 \expan0 \ul0 Tools\f1\b0\i0\outl0\shad0\fs20 \cf5 \expan0 \ul0 \u8482?\f1\b0\i0\outl0\shad0\fs20 \cf3 \expan0 \ul0  Worksheet.c window.\line ( 8) Type the same number of begin braces as the number of left arrow hits \line         you counted earlier.\line ( 9) Command V.\line (10) Command 1.\line (11) Command X.\line (12) Command S.\line (13) Switch back to your editor.\line (14) Command V.\line \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 \line I will be working in more user configurability but, until then, YOU have to do a little configuration on your own if you do not want your source to appear as \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  puts it out - but not much.\line \line If a brace is on the same line as an 'if' statement it will stay there.  If you want it on its own, new line, pre-edit by using a \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 Find/Replace\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  function in a text editor.  \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 Find\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  " {" (space leftBrace) and \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 Replace All\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  with "<cr>{" (return leftBrace) before running the formatter.  A Find/Replace function will be added to \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 , soon, so you can do this \u8220"in-house\u8221", but it will probably just be a part of the preferences.\line \line If you want to see how good this formatter is, preprocess a \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 small\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  source file, replace all RETURNs with a space, save the result and run the formatter on it!  \line \line If you intend to clean up \f0\b0\i0\outl0\shad0\fs28 \cf1 \expan0 \ul0 C\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 Tools\f0\b0\i0\outl0\shad0\fs28 \cf2 \expan0 \ul0 \u8482?\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  output from the Pascal to C function, you \f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0 MUST\f0\b0\i0\outl0\shad0\fs28 \cf0 \expan0 \ul0  edit it so that it has ALL matching braces, parens and semicolons first.  The technique for doing this is detailed in the Pascal to C section.\line }